package com.migo.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.migo.entity.MgAudioTypeEntity;
import com.migo.service.MgAudioTypeService;
import com.migo.utils.PageUtils;
import com.migo.utils.Query;
import com.migo.utils.R;


/**
 * 
 * 
 * @author powervision
 * @email zhenrong.xu@powervision.me
 * @date 2021-05-19 16:28:48
 */
@RestController
@RequestMapping("mgaudiotype")
public class MgAudioTypeController {
	@Autowired
	private MgAudioTypeService mgAudioTypeService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("mgaudiotype:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<MgAudioTypeEntity> mgAudioTypeList = mgAudioTypeService.queryList(query);
		int total = mgAudioTypeService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(mgAudioTypeList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{audioTypeId}")
	@RequiresPermissions("mgaudiotype:info")
	public R info(@PathVariable("audioTypeId") Integer audioTypeId){
		MgAudioTypeEntity mgAudioType = mgAudioTypeService.queryObject(audioTypeId);
		
		return R.ok().put("mgAudioType", mgAudioType);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("mgaudiotype:save")
	public R save(@RequestBody MgAudioTypeEntity mgAudioType){
		mgAudioTypeService.save(mgAudioType);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("mgaudiotype:update")
	public R update(@RequestBody MgAudioTypeEntity mgAudioType){
		mgAudioTypeService.update(mgAudioType);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("mgaudiotype:delete")
	public R delete(@RequestBody Integer[] audioTypeIds){
		mgAudioTypeService.deleteBatch(audioTypeIds);
		
		return R.ok();
	}
	
}
